package threads;
//多线程定时器类
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class TimeTest {
    public static void main(String [] args)throws InterruptedException
    {
        MyTask task=new MyTask();
        Timer time=new Timer();//构造定时器
        System.out.println("当前时间："+new Date());
        time.schedule(task,1000,2000);
        Thread.sleep(10000);
        task.cancel();
        System.out.println("====================");
        Calendar now=Calendar.getInstance();
        now.set(Calendar.SECOND,now.get(Calendar.SECOND)+3);
        Date runDate=now.getTime();
        Thread.sleep(5000);
        time.cancel();

    }
}
class MyTask extends TimerTask
{
    public void run()
    {
        System.out.println("现在运行时间为："+new Date());
    }
}
